<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ include file="/taglibs.jsp"%>
<s:url value="/images" var="imgPath"/>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/yaodian100.common.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css"/>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>'/>
<c-rt:set var="frontContextPath" value='<%=ServerValue.getFrontContextPath()%>'/>
<c-rt:set var="frontHostName" value='<%=ServerValue.getFrontHostname()%>'/>
<script type="text/javascript"> 
	$().ready(function(){
		$('#endDate').datepick({minDate: "+1D", showOn: 'both', 
		   	buttonImageOnly: true, buttonImage: '${imgPath}/calendar.gif',numberOfMonths:2,beforeShow:customRange,dateFormat:"yy-mm-dd",yearRange: '-50:+50'});

		if ( "" != $("#actId").val())
			$("#actLink").show();
		else{
			$('#startDate').datepick({minDate: new Date(), showOn: 'both', 
		    	buttonImageOnly: true, buttonImage: '${imgPath}/calendar.gif',numberOfMonths:2,dateFormat:"yy-mm-dd",yearRange: '-50:+50'});
			$("#actLink").hide();
		}
		
		$("#submit_button").click(function(){
			if ( validate_data() )
				$("#channelForm").submit();
		});
	});
	function validate_data(){
		if ( "" == $("#actName").val() ){
			alert("请输入活动名称");
			$("#actName").focus();
			return false;
		}
		if ( "2" != $('input[name=actType]<c-rt:if test="${empty channel.id}">:checked</c-rt:if>').val() ){
			if ( "" == $("#actUrl").val()){
				alert("请输入活动网址");
				$("#actUrl").focus();
				return false;
			}else{
				if ( !isURL("${frontHostName}" + $("#actUrl").val()) ){
					alert("活动网址格式错误");
					$("#actUrl").focus();
					return false;
				}
			}
		}
		if ( $("#actId").val() == "" ){
			if ( $("#startDate").val() == "" ){
				alert("请输入期间 起");
				$("#startDate").focus();
				return false;
			}
		}
		if ( $("#endDate").val() == "" ){
			alert("请输入期间 迄");
			$("#endDate").focus();
			return false;
		}
		return true;
	}
	function customRange (){
		var startDt = $('#startDate').val(); //起始日
		var endDt = new Date(parseInt(startDt.substring(0,4),10),parseInt(startDt.substring(5,7),10)-1,parseInt(startDt.substring(8,10),10)); //結束日
		return {minDate:endDt}; 
	}		
</script>
<h1>渠道广告管理<br/>
<div class="f-link">
	<a href="${midContextPath}/channel/search.do">回渠道管理列表页</a>
</div>
</h1>
<s:actionerror />
<s:actionmessage />
<s:fielderror />
<br/>
<s:form action="save.do" method="post" id="channelForm">
<table class="tb-data" width="100%">
		<tr>
			<th>活动代码</th>			
			<td>
				<c-rt:choose>
					<c-rt:when test="${empty channel.id}">系统流水号发放</c-rt:when>
					<c-rt:otherwise>${channel.id}</c-rt:otherwise>
				</c-rt:choose>
				<input type="hidden" id="actId" name="actId" value="${channel.id}"/>
			</td>
	  </tr>	
		<tr>
			<th>*渠道</th>			
			<td>        
		    <s:select id="channelName" name="channelName" list="channelNameMenu.options" listKey="key" listValue="value.name" value="%{channel.channelName}"/>
       </td>
	  </tr>
		<tr>
			<th >*活动类别</th>			
			<td>
				<c-rt:choose>
					<c-rt:when test="${empty channel.id}">
        		<s:radio id="actType" name="actType" list="channelTypeMenu.options" listKey="key" listValue="value.name" value="%{channel.actType}"/>
        	</c-rt:when>
        	<c-rt:otherwise>
        		${channelTypeMenu.options[channel.actType].name}
        		<input type="hidden" id="actType" name="actType" value="${channelTypeMenu.options[channel.actType].code}"/>
        	</c-rt:otherwise>
        </c-rt:choose>
      </td>
	  </tr>
	  <tr>
	  	<th>*活动名称</th>
	  	<td>
	  		<input type="text" id="actName" name="actName" value="${channel.actName}" maxlength="30" size="40"/>
	  	</td>
	  </tr>
		<tr>
	  	<th>*活动网址</th>
	  	<td>
	  		${frontHostName}<input type="text" id="actUrl" name="actUrl" value="${channel.actUrl}" maxlength="300" size="80"/><br/>
	  		※若为edm时,活动网址为非必填
	  	</td>
	  </tr>	  
	  <tr>
			<th>*活动日期起始时间</th>			
			<td>       
				<c-rt:choose>
					<c-rt:when test="${empty channel.id}">
						<input type="text" name="startDate" id="startDate" size="20" value="<fmt:formatDate value="${channel.startDate}" pattern="yyyy-MM-dd" />"/>	 
		     		<select id="startTime" name="startTime">			
							<c:forEach begin="0" end="23" var="t1">
								<c:if test="${t1<10}">
								<c:set value="0${t1}:00" var="sTime"></c:set>
								</c:if>
								<c:if test="${t1>=10}">
								<c:set value="${t1}:00" var="sTime"></c:set>
								</c:if>
								<option value="${sTime}" <c:if test="${sTime==startTime }">selected</c:if>>${sTime}</option>
							</c:forEach>
						</select>
					</c-rt:when>
					<c-rt:otherwise>
						<fmt-rt:formatDate value="${channel.startDate}" pattern="yyyy-MM-dd HH:mm"/>
						<input type="hidden" name="startDate" id="startDate" value="<fmt:formatDate value="${channel.startDate}" pattern="yyyy-MM-dd" />"/>
						<input type="hidden" name="startTime" id="startTime" value="<fmt:formatDate value="${channel.startDate}" pattern="HH:mm" />"/>
					</c-rt:otherwise>
				</c-rt:choose>
	    </td>
		</tr>
	  <tr>
			<th>*活动日期结束时间</th>			
			<td>        
		    <input type="text" name="endDate" id="endDate" size="20" value="<fmt:formatDate value="${channel.endDate}" pattern="yyyy-MM-dd" />"/>
		    <select id="endTime" name="endTime">
					<c-rt:forEach begin="0" end="23" var="t2" >
						<c-rt:set var="t3">${23-t2}</c-rt:set>	
						<c-rt:if test="${t3<10}">
						<c-rt:set value="0${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<c-rt:if test="${t3>=10}">
						<c-rt:set value="${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<option value="${eTime}" <c-rt:if test="${eTime==endTime }">selected</c-rt:if>>${eTime}</option>
					</c-rt:forEach>
				</select>
		  </td>
		</tr>
		<tr>
			<th>*上下架</th>
			<td>
				<s:select name="channelStatus" list="channelStatusMap" listKey="key"  listValue="value" value="%{channelStatus}"/>
			</td>
		</tr>
		<tr id="actLink">
			<th>广告连结</th>
			<td>
				<c-rt:set var="baseUrl">${frontHostName}${frontContextPath}/channel/ad.do?id=${channel.id}&site=${channel.channelName}</c-rt:set>
				<c-rt:choose>
				<c-rt:when test="${channel.actType eq '2'}">${baseUrl}&url=使用者自行输入广告连结</c-rt:when>
				<c-rt:otherwise>${baseUrl}</c-rt:otherwise>
				</c-rt:choose>
			</td>
		</tr>
</table>
*为必填资料
<div class="f-link">
	<a href="#" id="submit_button">存档</a>
</div>
</s:form>